package com.lemon.smartsafetynew.net.services;

import android.content.Context;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.Constants;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.http.UrlInfo;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.lemon.smartsafety.http.service.BaseHttpServices;
import com.lemon.smartsafetynew.entity.notice.NoticeItemVo;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;

/**
 * Created by Andrew on 2017/11/3.
 */

public class NoticeServices extends BaseHttpServices {

    public static final String TAG = "NoticeServices";

    public NoticeServices(Context context) {
        super(context);
    }

    /**
     * 初始化，等同使用构造函数
     *
     * @return
     */
    public static NoticeServices init() {
        return new NoticeServices(IApplication.context());
    }


    /**
     * 初始化，等同使用构造函数
     *
     * @param context
     * @return
     */
    public static NoticeServices init(Context context) {
        return new NoticeServices(context);
    }


    /**
     * 获取公告列表
     */
    public void getNoticeList(RefreshType type, LemonRequestParams params, String status) {

        HandlerCallback<List<NoticeItemVo>> callback = new HandlerCallback<List<NoticeItemVo>>(KeyConstants.URL_GET_NOTICE_LIST + status) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_NOTICE_LIST, Constants.SERVER_V2);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .params(params)
                .build().execute(callback);

    }

    /**
     * 读公告
     */
    public void readNoticeDetail(LemonRequestParams params) {

        HandlerCallback<NoticeItemVo> callback = new HandlerCallback<NoticeItemVo>(KeyConstants.URL_READ_NOTICE_DETAIL) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.READ_NOTICE_DETAIL, Constants.SERVER_V2);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .params(params)
                .build().execute(callback);

    }

}
